package com.yztc.orangeentertainment.ui.main.findfragment.findadapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.yztc.orangeentertainment.R;
import com.yztc.orangeentertainment.bean.findbean.FindChangeDataBean;
import com.yztc.orangeentertainment.ui.main.channalarticle.ChannalArticleActivity;

import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;

/**
 * Created by My on 2016/10/14.
 */
public class FindChangAdapter extends RecyclerView.Adapter<FindChangAdapter.ChangeViewHolder> {
    private List<FindChangeDataBean> list;
    private Context context;

    public FindChangAdapter(Context context, List<FindChangeDataBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public ChangeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        ChangeViewHolder holder = new ChangeViewHolder(LayoutInflater.from(context).inflate(R
                .layout.find_recyclerview, null));
        return holder;
    }

    @Override
    public void onBindViewHolder(ChangeViewHolder holder, final int position) {
        holder.rlvTv.setText(list.get(position).getTitle());
        holder.rlvTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ChannalArticleActivity.class);
                intent.putExtra("id", list.get(position).getId() + "");
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class ChangeViewHolder extends RecyclerView.ViewHolder {
        @InjectView(R.id.rlv_tv)
        TextView rlvTv;

        public ChangeViewHolder(View itemView) {
            super(itemView);
            ButterKnife.inject(this, itemView);
        }
    }
}
